<template>
  <div class="layout-all">
    <control :config="config" />
    <div class="layout-header" style="float:left" />
    <div class="layout-content">
      <el-table
        :data="tableData"
        stripe
        align="center"
        highlight-current-row
        style="width: 100%;margin-top:50px"
      >
        <el-table-column align="center" prop="title" label="群标题" />
        <el-table-column align="center" prop="description" label="群描述" width="250">
          <!-- <template slot-scope="scope">
            <img :src="scope.row.url" width="100%">
          </template> -->
        </el-table-column>
        <el-table-column align="center" prop="user_count" label="人数" />
        <el-table-column align="center" prop="creater.nickname" label="创建者" />
        <!-- <el-table-column prop="thumb" label="封面" width="100">
          <template slot-scope="scope">
            <img :src="scope.row.thumb" width="50%">
          </template>
        </el-table-column> -->
        <!-- <el-table-column prop="creater.sex" label="性别" width="120">
          <template slot-scope="scope">
            <el-tag
              v-if="scope.row.creater.sex === 1"
              type="primary"
              disable-transitions
            >男</el-tag>
            <el-tag
              v-if="scope.row.creater.sex ===0"
              type="primary"
              disable-transitions
            >女</el-tag>
            <el-tag
              v-if="scope.row.creater.sex === 2"
              type="primary"
              disable-transitions
            >未知</el-tag>
          </template>
        </el-table-column> -->
        <el-table-column align="center" prop="status" label="是否启用" width="80">
          <template slot-scope="scope">
            <el-button
              :type="scope.row.status === 1 ? 'primary' : 'success'"
              size="mini"
              @click="change_status(scope.row.id,'status' ,scope.row.status)"
            >{{ scope.row.status === 1 ? "是" : "否" }}</el-button>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="telephone"
          fixed="right"
          width="280"
          size="mini"
          label="操作"
        >
          <template slot-scope="scope">
            <router-link :to="'/group_abt/group/userList?id=' + scope.row.id">
              <el-button size="small" type="primary">群成员</el-button>
            </router-link>
            <router-link :to="'/group_abt/group/retailList?id=' + scope.row.id">
              <el-button size="small" type="success">分销</el-button>
            </router-link>
            <router-link :to="'/group_abt/group/noticeList?id=' + scope.row.id">
              <el-button size="small" type="info">群公告</el-button>
            </router-link>
            <!-- <el-button
              type="danger"
              icon="el-icon-delete"
              @click="onDel(scope.row.id)"
            /> -->
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- <el-pagination
      :current-page="current_page"
      :page-size="per_page"
      layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    /> -->
  </div>
</template>

<script>
import control from '../../components/control/control'
export default {
  components: { control },
  data() {
    return {
      config: [
        { type: 'text', placeholder: '请输入内容', field: 'title', val: '' }
      ],
      value: '',
      searchWhere: {
        title: ''
      },
      tableData: [],
      total: 0,
      current_page: 1,
      per_page: 14
    }
  },
  mounted() {
    this.onSearch()
  },
  methods: {
    // 查询
    handleSizeChange(val) {
      this.onSearch()
    },
    handleCurrentChange(val) {
      this.current_page = val
      this.onSearch()
    },
    onSearch() {
      // const form = {}
      // form.page = this.current_page
      // form.map = this.searchWhere
      this.get('/admin/group/index').then(e => {
        this.tableData = e.list.data
        this.per_page = e.list.per_page
        this.total = e.list.total
        this.current_page = e.list.current_page
      })
    },
    // 添加
    onAdd() {},
    // 编辑
    onEdit(id) {
      console.log(id)
    },
    // 修改状态
    change_status(id, field, val) {
      this.update(id, val, field, 'group').then(e => {
        e ? this.onSearch() : ''
      })
    },
    // 删除
    onDel(id) {
      this.$msg_confirm().then(e => {
        if (e) {
          this.get('/admin/group/del?id=' + id, this.form, 'POST').then(e => {
            this.onSearch()
          })
        }
      })
    }
  }
}
</script>

<style>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
</style>>
